#!/bin/sh
#
# Startup script for ser2net
#

start() {
    printf  "Starting ser2net: "
    if [ ! -f /usr/local/etc/ser2net.conf ] ; then
      echo "disabled"
      exit 1
    fi

    if start-stop-daemon -S -q --exec /usr/sbin/ser2net -- -c /usr/local/etc/ser2net.conf -P /var/run/ser2net.pid; then
      echo "OK"
    else
      echo "FAIL"
    fi
}

stop() {
    printf "Shutting down ser2net: "
    if [ ! -f /var/run/ser2net.pid ] ; then
      echo "OK"
      return
    fi

    if start-stop-daemon -K -q -p /var/run/ser2net.pid; then
      echo "OK"
    else
      echo "FAIL"
    fi
}

restart() {
    stop
    start
}

case "$1" in
	start)
	    start
	    ;;
	stop)
	    stop
	    ;;
	restart)
	    restart
	    ;;
	*)
	    echo "Usage: ser2net {start|stop|restart}"
	    exit 1
esac

exit 0
